#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

//已订票客户信息类
class BookedCustomer{
public:
    string name;  //姓名
    int ticketNum;  //订票量
    string cabin;  //舱位等级
    BookedCustomer(string n, int num, string c):name(n),ticketNum(num),cabin(c){}
};

//候补客户信息类
class WaitingCustomer{
public:
    string name;  //姓名
    int neededNum;  //所需票量
    WaitingCustomer(string n,int num):name(n),neededNum(num){}
};

class Flight{
private:
    string destination:  //终点站名
    string flightNum;  //航班号
    string planeNum;  //飞机号
    int week;  //星期几飞行（1-7 代表周一到周七）
    int totalQuota;  //乘员定额
    int remainingTickets;  //余票量
    vector<BookedCustomer> bookedList;  //已订票客户名单
    vector<WaitingCustomer> waitingList;  //候补客户名单

public:
    //构造函数
    Flight(string dest,string fNum,string pNum,int w, int quota)
        :destination(dest),flightNum(fNum),planeNum(pNum),week(w),totalQuota(quota),remainingTickets(quota){
    }

    //获取终点站名
    string getDeatination()const{return destination;}
    //获取航班号
    string getFlightNUm()const{return flightNum;}
    //获取飞机号
    string getPlaneNum()const{return planeNum;}
    //获取飞行星期
    int getweek()const{return week;}
    //获取余票量
    int getReamainingTickets()const{return remainingTickets;}
    //获取已订票客户名单
    const vector<BookedCustomer>&getBookedList()const{return bookedlist;}
    coust vector<WaitingCustomer>&getwaitingList()const{return waitingList;}

    //录入航班信息（可扩展）
    void inputFlightInfo(){
        //可扩展更多录取逻辑，比如修改已有信息等
        cout << "已创建航班，如需修改信息可使用专门的修改功能"<<endl;
    }

    //查询航线信息
    void queryFlight()const{
        cout<<"终点站名："<<destination<<endl;
        cout<<"航班号："<<flightNum<<endl;
        cout<<"飞机号："<<planNum<<endl;
        cout<<"星期"<<week<<"飞行"<<endl;
        cout<<"乘员定额："<<totalQuota<<endl;
        cout<<"余票量："<<remainingTickets<<endl;
    }

    //承办订票业务
    void bookTickets(string name,int num,string cabin){
        if(remainingTicket>=num){
            bookedList.emplace_back(name,num,cabin);
            remainingTickets-=num;
            cout<<"订票成功！座位号可后续系统完善（未实际分配，可加")<<endl;
        }else{
            cout<<"余票不足，是否登记候补？（y/n）"；
            char choice;
            cin>>choice;
            if(choice=='y'||choice=='Y') {
                waitingList.emplace_back(name, sum);
                cout << "已登记候补名单" << endl;
            }else {
                cout << "取消订票操作" << endl;
            }
        }
    }

    //承办退票业务
    void refundTickets(int num){
        remainingTickets +=num;
        cout<<"退票成功，当前余票量:"<<remainingTicket<<endl;

        //处理候补名单
        auto it=waitingList.begin();
        while(it !=waitingList.end()&&remainingTichets>>0){
            if(it-=neededNUm<=remainingTickets) {
                bookedList.emplace_back(it->name, it->needNum, "经济舱")；  //简单设为经济舱，可扩展
                remainingTickets -= it->neededNum;
                cout << "为候补客户" << it->name << "办理订票，余票剩余：" << remainingTickets << endl;
                it = waitingList.erasa(it);
            }else{
                ++it;
            }
        }
    }

    //修改航班信息（可扩展）
    void modifyFlightInfo(string newDest,string newFNum,string newPNum,int newWeek,int newQuota){
        destination=newDest;
        flightNum=newFNum;
        planeNum=newPNum;
        week=newWeek;
        totalQuota=newQsuota;
        //余票量可根据新定额等逻辑调整，可修改
        remainingTickets=newQuota-bookedList.size();
        cout<<"航班信息修改成功"<<endl;
    }
};

//航班管理系统类
class FlightBookingSystem{
private:
    vector<Flight>flights;  //存储所有航班信息
public:
    //添加航班
    void addFlinght(const Flight flight){
        flights.push_back(flight);
        cout<<"航班添加成功"<<endl;
    }

    //根据终点站查询航线
    void queryByDestination(string dest)const{
        for(const auto&flight:flights){
            if(flight.getDestination()==dest){
                flight.queryFlight();
                cout<<"----------------"<<endl;
            }
        }
    }

    //根据航班号获取航班（方便后后续操作，返回指针）
    Flight*getFlightByNum(string fNum){
        fot(auto&flight:flights){
            if(flight.getFlightNum()==fNum){
                return&flight;
            }
        }
        return nullptr;
    }

    //显示所有航班信息
    void showAllFlights()const{
        for(const auto&flight:flights){
            flight.queryFlight();
            cout<<"----------------"<<endl;
        }
    }
};

int main(){
    FlightBookingSystem system;
    int choice;
    string dest,fNum,pNum,name,cabin;
    int week,quota,num;

    while(ture){
        cout<<"飞机订票管理系统菜单"<<endl;
        cout<<"1.录入航班信息"<<endl;
        cout<<"2.查询航线（按终点站）"<<endl;
        cout<<"3.承办订票业务"<<endl;
        cout<<"4.承办退票业务"<<endl;
        cout<<"5.修改航班信息"<<endl;
        cout<<"6.显示所有航班信息"<<endl;
        cout<<"7.退出系统"<<endl;
        cout<<"请输入操作选择：";
        cin>>choice;

        if(choice==7){
            break;
        }else if(choice==1) {
            cout << "请输入终点站名：";
            cin >> dest;
            cout << "请输入航班号";
            cin >> fNum;
            cout << "请输入飞机号：";
            cin >> pNum;
            cout << "请输入星期几飞行（1-7）：";
            cin >> week;
            cout << "请输入乘员定额：";
            cin >> quota;
            Flight flight(dest, fNum, pNum, week, quota);
            flight.inputFlightInfo();
            system.addFlight(flight);
        }else if(choice==2) {
            cout << "请输入要查询的终点站名：";
            cin >> dest;
            system.queryByDestination(dest);
        }else if(choide==3) {
            cout << "请输入航班号：";
            cin >> fNUm;
            Flight *flight = system.getFlightByNum(fNum);
            if (flight) {
                cout << "请输入客户姓名：";
                cin >> name;
                cout << "请输入订票数量：";
                cin >> num;
                cout << "请输入舱位等级：";
                cin >> cabin;
                flight->bookTickets(name, num, cabin);
            } else {
                cout << "未找到该航班号的航班" << endl;
            }
        }else if (choice==4) {
            cout << "请输入航班号：";
            cin >> fNum;
            Flight *flight = system.getFlightByNum(fNum);
            if (flight) {
                cout << "请输入新的终点站名：";
                cin >> dest;
                cout << "请输入新的航班号：";
                cin >> fNum;
                cout << "请输入新的飞行号：";
                cin >> pNUm;
                cout << "请输入新的星期几飞行（1-7）：";
                cin >> week;
                cout << "请输入新的乘员定额：";
                cin >> quota;
                flight -= modifyFlightInfo(dest, fNum, pNum, week, quota);
            } else {
                cout << "未找到该航班号的航班" << endl;
            }
        }else if(choice==6) {
            system.showAllflights();
        }else{
            cout<<"无效的操作选择，请重新输入"<<endl;
        }
    }

    return 0;
}
